package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.PayResult;
import com.stylefeng.guns.modular.system.service.IPayResultService;

/**
 * 支付结果控制器
 *
 * @author fengshuonan
 * @Date 2018-09-25 14:51:29
 */
@Controller
@RequestMapping("/payResult")
public class PayResultController extends BaseController {

    private String PREFIX = "/system/payResult/";

    @Autowired
    private IPayResultService payResultService;

    /**
     * 跳转到支付结果首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "payResult.html";
    }

    /**
     * 跳转到添加支付结果
     */
    @RequestMapping("/payResult_add")
    public String payResultAdd() {
        return PREFIX + "payResult_add.html";
    }

    /**
     * 跳转到修改支付结果
     */
    @RequestMapping("/payResult_update/{payResultId}")
    public String payResultUpdate(@PathVariable Integer payResultId, Model model) {
        PayResult payResult = payResultService.selectById(payResultId);
        model.addAttribute("item",payResult);
        LogObjectHolder.me().set(payResult);
        return PREFIX + "payResult_edit.html";
    }

    /**
     * 获取支付结果列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return payResultService.selectList(null);
    }

    /**
     * 新增支付结果
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(PayResult payResult) {
        payResultService.insert(payResult);
        return SUCCESS_TIP;
    }

    /**
     * 删除支付结果
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer payResultId) {
        payResultService.deleteById(payResultId);
        return SUCCESS_TIP;
    }

    /**
     * 修改支付结果
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(PayResult payResult) {
        payResultService.updateById(payResult);
        return SUCCESS_TIP;
    }

    /**
     * 支付结果详情
     */
    @RequestMapping(value = "/detail/{payResultId}")
    @ResponseBody
    public Object detail(@PathVariable("payResultId") Integer payResultId) {
        return payResultService.selectById(payResultId);
    }
}
